<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'vip折扣比例设置')">
            vip折扣比例设置 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.vipRate}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'svip折扣比例设置')">
            svip折扣比例设置 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.svipRate}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'一级返佣比例设置')">
            一级返佣比例设置 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div  class="item2">
            {{form2.oneRate}}
          </div>
        </el-card>
      </el-col>



    </el-row>
    <el-row :gutter="20" style="margin-top: 1.4rem">
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div  class="text item" @click="handleUpdate(form2,'二级返佣比例设置')">
            二级返佣比例设置 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.twoRate}}
          </div>
        </el-card>
      </el-col>

      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div  class="text item" @click="handleUpdate(form2,'最低提现金额设置')">
            最低提现金额设置 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.lowestAmt}}
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20"  style="margin-top: 1.4rem">
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'vip1每天下载数量')">
            vip1每天下载数量 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.vip1Num}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'vip2每天下载数量')">
            vip2每天下载数量 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.vip2Num}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'vip3每天下载数量')">
            vip3每天下载数量 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div  class="item2">
            {{form2.vip3Num}}
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20"  style="margin-top: 1.4rem">
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'vip1返佣积分')">
            vip1返佣积分 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.vip1Amt}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'vip2返佣积分')">
            vip2返佣积分 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div class="item2">
            {{form2.vip2Amt}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card" shadow="always">
          <div class="text item" @click="handleUpdate(form2,'vip3返佣积分')">
            vip3返佣积分 <span class="text item" style="margin-left: 5rem">〉</span>
          </div>
          <div  class="item2">
            {{form2.vip3Amt}}
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 添加或修改参数设置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="400px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="10px">
        <el-form-item prop="vipRate" v-if="title == 'vip折扣比例设置'">
          <label>vip折扣比例</label>
          <el-input v-model="form.vipRate" placeholder="请输入vip折扣比例">
<!--            <template slot="append">%</template>-->
          </el-input>
        </el-form-item>
        <el-form-item prop="svipRate" v-if="title == 'svip折扣比例设置'">
          <label>svip折扣比例</label>
          <el-input v-model="form.svipRate" placeholder="请输入svip折扣比例" />
        </el-form-item>
        <el-form-item prop="oneRate" v-if="title == '一级返佣比例设置'">
          <label>一级返佣比例</label>
          <el-input v-model="form.oneRate" placeholder="请输入一级返佣比例" />
        </el-form-item>
        <el-form-item prop="twoRate" v-if="title == '二级返佣比例设置'">
          <label>二级返佣比例</label>
          <el-input v-model="form.twoRate" placeholder="请输入佣金比例">
<!--            <template slot="append">%</template>-->
          </el-input>
        </el-form-item>
        <el-form-item prop="lowestAmt" v-if="title == '最低提现金额设置'">
          <label>最低提现金额</label>
          <el-input v-model="form.lowestAmt" placeholder="请输入最低提现金额">
<!--            <template slot="append">%</template>-->
          </el-input>
        </el-form-item>

        <el-form-item prop="vip1Num" v-if="title == 'vip1每天下载数量'">
          <label>vip1每天下载数量</label>
          <el-input v-model="form.vip1Num" placeholder="请输入vip1每天下载数量">
          </el-input>
        </el-form-item>

        <el-form-item prop="vip2Num" v-if="title == 'vip2每天下载数量'">
          <label>vip2每天下载数量</label>
          <el-input v-model="form.vip2Num" placeholder="请输入vip2每天下载数量">
          </el-input>
        </el-form-item>

        <el-form-item prop="vip3Num" v-if="title == 'vip3每天下载数量'">
          <label>vip3每天下载数量</label>
          <el-input v-model="form.vip3Num" placeholder="请输入vip3每天下载数量">
          </el-input>
        </el-form-item>

        <el-form-item prop="vip1Amt" v-if="title == 'vip1返佣积分'">
          <label>vip1返佣积分</label>
          <el-input v-model="form.vip1Amt" placeholder="请输入vip1返佣积分">
          </el-input>
        </el-form-item>

        <el-form-item prop="vip2Amt" v-if="title == 'vip2返佣积分'">
          <label>vip2返佣积分</label>
          <el-input v-model="form.vip2Amt" placeholder="请输入vip2返佣积分">
          </el-input>
        </el-form-item>

        <el-form-item prop="vip3Amt" v-if="title == 'vip3返佣积分'">
          <label>vip3返佣积分</label>
          <el-input v-model="form.vip3Amt" placeholder="请输入vip3返佣积分">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDSystemSettings, getDSystemSettings, delDSystemSettings, addDSystemSettings, updateDSystemSettings } from "@/api/video/DSystemSettings";

export default {
  name: "DSystemSettings",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 系统设置表格数据
      DSystemSettingsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vipRate: null,
        svipRate: null,
        oneRate: null,
        twoRate: null,
        lowestAmt: null,
      },
      // 表单参数
      form: {},
      form2: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询系统设置列表 */
    getList() {
      this.loading = true;
      listDSystemSettings(this.queryParams).then(response => {
        this.DSystemSettingsList = response.rows;
        if (response.rows.length > 0){
          this.form2 = response.rows[0];
        }
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        vipRate: null,
        svipRate: null,
        oneRate: null,
        twoRate: null,
        lowestAmt: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加系统设置";
    },
    /** 修改按钮操作 */
    handleUpdate(row,title) {
      this.reset();
      const id = row.id || this.ids
      getDSystemSettings(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = title;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDSystemSettings(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDSystemSettings(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除系统设置编号为"' + ids + '"的数据项？').then(function() {
        return delDSystemSettings(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('video/DSystemSettings/export', {
        ...this.queryParams
      }, `DSystemSettings_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.text {
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
}

.item {
  padding: 10px 0;
}
.item2 {
  padding: 20px 0;
  font-size: 3.6rem;
  font-weight: bold;
}
</style>
